package com.qing.springboot01.controller;


import com.qing.springboot01.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@RestController
@Slf4j
public class ImageUploadController {

    @Value("${reggie.path}")
    private String path;

    @PostMapping("/common/upload")
    public R<String> getImage(MultipartFile file) throws IOException {
        String filename = file.getOriginalFilename();
//        String suffix = filename.substring(filename.lastIndexOf("."));//获取后缀名
//        log.info("filename+suffix:{}",filename+suffix);

        File f = new File(path + "\\" + filename);
        file.transferTo(new File(path+filename));
        return R.success(filename);
    }
}
